package cn.zkrt.iotms.interceptor;

import cn.zkrt.iotms.config.FeignTokenSupportConfig;
import cn.zkrt.iotms.feign.token.TokenContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;

public class FeignTokenRequestInterceptor implements RequestInterceptor{


    @Autowired
    private TokenContext tokenProvider;

    @Override
    public void apply(RequestTemplate template) {
        String token = tokenProvider.getCurrentToken();
        if (token!= null) {
            template.header("Authorization",token);
        }else {
            template.header("Authorization", FeignTokenSupportConfig.SPECIAL_AUTHORIZATION);
        }
    }
}
